

<template>

  <div >
         
          <el-form
            label-position="right"
            label-width="120px"
           
          >
          <el-col :span="6">
            <el-form-item label="经办人姓名">
              <el-input
                v-model="jingbanname"
                
              ></el-input>
            </el-form-item>
             </el-col>
              <el-col :span="6">
            <el-form-item label="经办人身份证号">
               <el-input
                v-model="jingbanidcrdid"
              @blur="getInfo2(jingbanidcrdid)"
              ></el-input>
              </el-form-item>
            </el-col>
          </el-form>
       <el-col :span="6">
       <el-button  class="butB_Sel"  @click="printBtn()">打印</el-button>
 </el-col>
    <div class="app-container" id="printcons" >
  <div :style="it==0?'width:800px;padding:0px 40px;paddingTop:40px;height:1050px;font-size:20px':style2" v-for="(item2,it) in drug2" :key="it">
     <el-row>
    <el-col :span="20">
  <h1 style="text-align: center;">{{his_name}}处方笺</h1>
   </el-col>
   <el-col :span="4">
  <h1 style="text-align: center;">精二</h1  >
   </el-col>
    </el-row>
   <div  style=" margin: 10px 0px;">
       <el-row>
          <el-col :span="6">
       科室:{{dept_info_name}}
       </el-col>
        <el-col :span="8" >
      费用:{{fee_category_name}}
        </el-col>
                <el-col :span="8">
         时间:{{cfdata.created_at}}
</el-col>
  </el-row>
   </div>
    <div style="height: 50px;

    border-top: 2px solid;
    
    box-sizing: border-box;
      

    ">
       <el-row>
    
   <el-col :span="6" style=" line-height: 50px;">
       姓名:{{cfdata.member.name}}
             </el-col>
                <el-col :span="4" style=" line-height: 50px;">
       性别:{{cfdata.member.gender==1?'男':cfdata.member.gender==2?'女':'其他'}}
           </el-col>
                 <el-col :span="4" style=" line-height: 50px;">
        年龄:{{cfdata.member.age}}岁
</el-col>
 <el-col :span="10" style="line-height: 50px;" >
      
       门诊号:{{cfdata.patient_no}}

         
        </el-col>
          </el-row>
       
           </div>
  
 
       
<div style="height: auto;

    border-top: 2px solid;
    
    box-sizing: border-box;
    

    ">
       <el-row>
    
   <el-col :span="24" style="line-height: 30px;">
      <div >住址: {{cfdata.member.address}}
       </div>  
             </el-col>
      
 <el-col :span="24" style=" line-height: 30px;">
  身份证明编号:{{cfdata.member.id_card}}
        </el-col>
          </el-row>
       
           </div>

<div style="height: 50px;

    border-top: 2px solid;
  
    box-sizing: border-box;
      

    ">
       <el-row>
    
   <el-col :span="7" style=" line-height: 50px;">
       经办人姓名:{{jingbanname}}
             </el-col>
                <el-col :span="3" style=" line-height: 50px;">
       性别:{{jingbangender==1?'男':jingbangender==2?'女':''}}
           </el-col>
                 <el-col :span="3" style=" line-height: 50px;">
        年龄:{{jingbanage}}
</el-col>
  <el-col :span="11" style=" line-height: 50px;">
  身份证明编号:{{jingbanidcrdid}}
        </el-col>
          </el-row>
       
           </div>
    <div style="min-height: 50px
    line-height: 50px;
   border-top: 2px solid;
    border-bottom: 2px solid;
    box-sizing: border-box;
        margin: 5px 0px;

    ">
    <el-row>
     <!-- <el-col :span="4">
      临床症状:
        </el-col>
<el-col :span="20" >
   {{cfdata.medical_record.diagnosis.length!=0?cfdata.medical_record.diagnosis[0].name:''}}
        </el-col> -->
     <el-col :span="4">
      临床诊断:
        </el-col>
<el-col :span="20" >
    {{cfdata.medical_record.diagnosis.length!=0?cfdata.medical_record.diagnosis[0].name:''}}
        </el-col>
         </el-row>
    </div>
    <!-- <div style="text-align: center;border-bottom: 1px solid;">
        <el-row>
            <el-col :span="1">
                &nbsp;
            </el-col>
            <el-col :span="7">
                药品名称
            </el-col>
              <el-col :span="4">
                药品规格
            </el-col>
              <el-col :span="4">
                一次剂量
            </el-col>
              <el-col :span="4">
                数量
            </el-col>
               <el-col :span="4">
                单价
            </el-col>
        </el-row>
    </div> -->
     <div style="height:550px">
          <el-col :span="1" >
                   <h2 style="margin:0px">R:</h2>
            </el-col>
            <el-col :span="22">
        <el-row  v-for="(item,index) in item2" :key="index">
       
            
           <el-col :span="10" style="margin-top:40px">
              
               {{item.drug.name}}
            </el-col>
              <el-col :span="7" style="margin-top:40px">
              {{item.drug.specification}}
            </el-col>
              <el-col :span="2" style="margin-top:40px">
            &#12288;
            </el-col>
              <el-col :span="3" style="margin-top:40px">
               {{item.num}} {{item.drug.base_unit}}
            </el-col>
               <el-col :span="2" style="margin-top:40px">
                {{item.price}}
            </el-col>
            <el-col :span="24" :offset="2" style="margin-top:20px">

                  用法 : {{item.dose}}{{item.dose_unit}} &#12288;  {{item.drug.usage}} &#12288;  {{item.drug.each_dos}}
  </el-col>
        </el-row>
        </el-col>
    </div>
  备注:  {{cfdata.remark}} 
    <div style="height: 35px;
    line-height: 35px;
    border-top: 2px solid;
    border-bottom: 2px solid;
    box-sizing: border-box;


    ">
 
  <el-row>
   
                <el-col :span="8" style="padding-left:5px">
      医师:{{cfdata.doctor.real_name}}
        </el-col>
                   <el-col :span="8"  style="padding-left:5px;border-left: 2px solid;border-right: 2px solid;">
      药价:{{cfdata.should_amount}}
        </el-col>
                       <el-col :span="8" style="padding-left:5px">
      其他:
        </el-col>
          </el-row>
 
    </div>
      <div style="height: 35px;
    line-height: 35px;
  
    border-bottom: 2px solid;
    box-sizing: border-box;


    ">
    <el-row>
       <el-col :span="8" style="padding-left:5px" >
      调剂:
        </el-col>
    
    
         <el-col :span="8" style="padding-left:5px;border-left: 2px solid;border-right: 2px solid;" >
      核对、发药:
        </el-col>
       <el-col :span="8" style="padding-left:5px">
      取药:
        </el-col>
         </el-row>
    </div>
    <div>
        备注:该处方及申请单仅限当日当次使用:谢谢配合
    </div>
        </div>
                 </div>
  </div>
</template>
<script>


export default {
		// props:['cfdata'],
  data() {
    return {
  tabeldata:{},
  sourcelist:[],
  drug2:[],
   dayin:false,
    style2:{
    width:"800px",padding:"0px 40px",
    marginTop:"0",
    height:"1150px",
    fontSize:'20px',
    paddingTop:"40px"
  },
   jingbangender:'',
   jingbanage:'',
   jingbanidcrdid:'',
   jingbanname:'',
   fee_category_name:'',
   cfdata:{},
   dept_info_name:'',
    his_name:process.env.VUE_APP_HOSPITAL_API2,
    };
  },
  
  mounted(){
    this.drug2=[]
        this.cfdata =JSON.parse(this.$route.query.cfdata)
        console.log(this.cfdata)
        this.dept_info_name=this.cfdata.dept_info==undefined?this.cfdata.dept_name:this.cfdata.dept_info.name
   var arr=this.cfdata.drug
    if(this.cfdata.drug.length>5){
 
      for (let i = 0; i < Math.ceil(arr.length/5); i++) {
     this.drug2.push(arr.slice(i*5,5*(i+1)));
      
    }
    console.log(this.drug2)
    }else{

    this.drug2.push(arr)
    }
     this.fee_category_name=this.drug2[0][0].drug.fee_category.name
      
    
  },
  //  watch: {
 
  //   cfdata(n) {
	// 		console.log(n.drug,'0000')
  //     var arr=n.drug
  //    if(arr.length>5){

  //     for (let i = 0; i < Math.ceil(arr.length/5); i++) {
  //    this.drug2.push(arr.slice(i*5,5*(i+1)));
  //     this.fee_category_name=this.drug2[0][0].drug.fee_category.name
  //   }
   
  //   }else{

  //     this.drug2.push(arr)
  //     this.fee_category_name=this.drug2[0][0].drug.fee_category.name
  //   }
  //    console.log(this.drug2,'000000')
	// },
  
    
  //   },

  methods: {
        getInfo2(idCard) {
        let sex = null;
        let birth = null;
        let myDate = new Date();
        let month = myDate.getMonth() + 1;
        let day = myDate.getDate();
        let age = 0;

        if (idCard.length === 18) {
          age = myDate.getFullYear() - idCard.substring(6, 10) - 1;
          sex = idCard.substring(16, 17);
          birth = idCard.substring(6, 10) + "-" + idCard.substring(10, 12) + "-" + idCard.substring(12, 14);
          if (idCard.substring(10, 12) < month || idCard.substring(10, 12) === month && idCard.substring(12, 14) <= day)
            age++;

        }
        if (idCard.length === 15) {
          age = myDate.getFullYear() - idCard.substring(6, 8) - 1901;
          sex = idCard.substring(13, 14);
          birth = "19" + idCard.substring(6, 8) + "-" + idCard.substring(8, 10) + "-" + idCard.substring(10, 12);
          if (idCard.substring(8, 10) < month || idCard.substring(8, 10) === month && idCard.substring(10, 12) <= day)
            age++;
        }

        if (sex % 2 === 0)
          sex = 0; // 性别代码 1代表男，0代表女，暂时不涉及其他类型性别
        else
          sex = 1;
           this.jingbangender=sex
          if(age==0){
              this.jingbanage=''
          }else{
                       this.jingbanage=age+'岁'
          }

       
  
      },
	  getindex(){
		  	getdictIndex({group_id:'40'}).then(res=>{
				let data = res.data;
				  data.forEach((item, key) => {
				if(item.id==40){
            
             this.sourcelist=item.items;
            } 
			 })
			  })
	  },
	  getpint(){
		  	       this['_API'].getPrintReport({id:this.id}).then(res=>{
                            if(res.code==200){
                               this.tabeldata=res.data
								this.tabeldata.source=this.mapxing(this.tabeldata.source)
								
							}
                    })
	  },
	 
	    mapxing(num) {
      var art = "";
         this.sourcelist.map(function(value,i,array){
            
            if (value.id == num) {
          art = value.name;
        }
        
       })
	   console.log(art)
        return art;  
    },
        printBtn(e) {
            this.dayin=true
         setTimeout(() => {
      this.dayinfun()
     }, 200);
     
    },
        dayinfun(){
             this.remove_ie_header_and_footer();
      let subOutputRankPrint = document.getElementById("printcons");
      console.log(subOutputRankPrint.innerHTML);
      let newContent = subOutputRankPrint.innerHTML;
      let oldContent = document.body.innerHTML;
      document.body.innerHTML = newContent;
      window.print();
      window.open('','_self').close(),
      document.body.innerHTML = oldContent;
      return false;
        },
    //去掉页眉和页脚
    remove_ie_header_and_footer() {
      var hkey_path;
      hkey_path =
        "HKEY_CURRENT_USER\\Software\\Microsoft\\Internet Explorer\\PageSetup\\";
      try {
        var RegWsh = new ActiveXObject("WScript.Shell");
        RegWsh.RegWrite(hkey_path + "header", "");
        RegWsh.RegWrite(hkey_path + "footer", "");
      } catch (e) {}
    },

    
    
  },
   
};
</script>
<style media="print">
				@page {
				  size: auto; /* auto is the initial value */
				  margin: 0mm; /* this affects the margin in the printer settings */
				}
				@media print {
				}
				body {
				  -webkit-print-color-adjust: exact;
				}
				   #printcons{
                 
                       margin: auto;
                       box-sizing: border-box;
                    
                   }
				</style>
<style lang='scss' scoped>
.juzhong{
   display: flex;
          align-items: center;/*如果flex-direction：row；代表垂直居中 ；如果flex-direction：column；则代表水平居中*/
          justify-content: center;/*如果flex-direction：row；代表水平居中；如果flex-direction：column；则代表垂直居中*/
      
          width: 100%;
          height: 100%;     

}
		


</style>